package com.cy;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

@SpringBootApplication
public class NacosProviderApplication {
    /**
     * 服务器启动时，会自动向nacos发送一个http请求
     * spring-cloud-starter-alibaba-nacos-discovery在这个依赖中，然后
     * 将这个服务注册到nacos服务端，nacos服务端会通过一个map来存储这个服务信息
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(NacosProviderApplication.class, args);
    }
    @Value("${server.port}")
    private String server;
    //内部类
    @RestController
    public class ProviderController{
        @GetMapping("/provider/echo/{string}")
        public String doEcho(@PathVariable String string, HttpServletRequest request){
//            Enumeration<String> headerNames = request.getHeaderNames();
//            while (headerNames.hasMoreElements()){
//                System.out.println(headerNames.nextElement());
//            }
            return server+"say:Hello Nacos Discovery "+string;
        }
    }
}
